﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class DatabaseHelpr
    {
        private readonly string sqlCommandString = "select * from QQ";
        private readonly string connectionString = "Server=.;database=LIN;uid=sa;pwd=lmt732118";

        public static void PrintUser()
        {
            String connectionString = "Server=.;database=LIN;uid=sa;pwd=lmt732118";

            SqlConnection sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();

            var sqlCommandString = "select * from QQ";

            SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);

            var sa = sqlCommand.ExecuteReader();

            while (sa.Read())
            {
                Console.WriteLine("\t{0}\t{1}", sa["ID"], sa["Age"]);
            }
            sqlConnection.Close();
        }

        public void GteUser()
        {
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommandString, connectionString);

            DataTable dataTable = new DataTable();

            dataAdapter.Fill(dataTable);
            Console.WriteLine(" ");
            Console.WriteLine(" ");
            Console.WriteLine(" ");

            Console.WriteLine("\t{0}\t{1}\t", "ID", "Age");

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("\t{0}\t{1}", dataTable.Rows[i]["ID"], dataTable.Rows[i]["Age"]);
            }
        }
    }
}